package com.order.dao;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class PageDBUtil {
	
	public static int getAllPage(int count,int span){
		int result=0;
		result=count/span+((count%span==0)?0:1);
		return result;
	}
   public static List<String[]> getPageContent(int paramenum,int page,int span,ResultSet rs){
	   List<String []> list=new ArrayList<String[]>();
	   try{
		   int first=(page-1)*span+1;
		   if(first!=1){
			   rs.absolute(first-1);
			   System.out.println(first);
		   } 
		   int c=1;
		   while(c<=span&&rs.next()){
			  
			   String str[]=new String[paramenum];
			   for(int i=0;i<paramenum;i++){
				   str[i]=rs.getString(i+1);
			   }
			   list.add(str);
			   c++;
			   
		   }
		   rs.close();
	   }catch(Exception e){
		   e.printStackTrace();
	   }
	   
	   
	   return list;
   }
   public static void main(String args[]){
	   //ResultSet rs=DBUtil.getAllManager();
	   ResultSet rs=DBUtil.getAllWaiter();
	   int count=DBUtil.getAllNum("waiterinfo");
       int pages=PageDBUtil.getAllPage(count, 2);
       System.out.println(pages);
       List<String[]> list=PageDBUtil.getPageContent(3,3,2,rs);
      for(String st[]:list){
    	   System.out.println(st[0]);
    	   System.out.println(st[1]);
    	   System.out.println(st[2]);
       }
     // System.out.println(list);
   }
}
